<?php

namespace App\Http\Controllers\Backend;

use App\DataTables\ItemContractDataTable;
use App\Http\Requests;
use App\Http\Requests\CreateItemContractRequest;
use App\Http\Requests\UpdateItemContractRequest;
use App\Repositories\ItemContractRepository;
use Flash;
use App\Http\Controllers\AppBaseController;
use Response;

class ItemContractController extends AppBaseController
{
    /** @var  ItemContractRepository */
    private $itemContractRepository;

    public function __construct(ItemContractRepository $itemContractRepo)
    {
        $this->itemContractRepository = $itemContractRepo;
    }

    /**
     * Display a listing of the ItemContract.
     *
     * @param ItemContractDataTable $itemContractDataTable
     * @return Response
     */
    public function index(ItemContractDataTable $itemContractDataTable)
    {
        return $itemContractDataTable->render('backend.item_contracts.index');
    }

    /**
     * Show the form for creating a new ItemContract.
     *
     * @return Response
     */
    public function create()
    {
        return view('backend.item_contracts.create');
    }

    /**
     * Store a newly created ItemContract in storage.
     *
     * @param CreateItemContractRequest $request
     *
     * @return Response
     */
    public function store(CreateItemContractRequest $request)
    {
        $input = $request->all();

        $itemContract = $this->itemContractRepository->create($input);

        Flash::success(trans('flash.controller.save_success', ['model' => 'Item Contract']));

        return redirect(route('itemContracts.index'));
    }

    /**
     * Display the specified ItemContract.
     *
     * @param  int $id
     *
     * @return Response
     */
    public function show($id)
    {
        $itemContract = $this->itemContractRepository->findWithoutFail($id);

        if (empty($itemContract)) {
            Flash::error(trans('flash.controller.not_found', ['model' => 'Item Contract']));

            return redirect(route('itemContracts.index'));
        }

        return view('backend.item_contracts.show')->with('itemContract', $itemContract);
    }

    /**
     * Show the form for editing the specified ItemContract.
     *
     * @param  int $id
     *
     * @return Response
     */
    public function edit($id)
    {
        $itemContract = $this->itemContractRepository->findWithoutFail($id);

        if (empty($itemContract)) {
            Flash::error(trans('flash.controller.not_found', ['model' => 'Item Contract']));

            return redirect(route('itemContracts.index'));
        }

        return view('backend.item_contracts.edit')->with('itemContract', $itemContract);
    }

    /**
     * Update the specified ItemContract in storage.
     *
     * @param  int              $id
     * @param UpdateItemContractRequest $request
     *
     * @return Response
     */
    public function update($id, UpdateItemContractRequest $request)
    {
        $itemContract = $this->itemContractRepository->findWithoutFail($id);

        if (empty($itemContract)) {
            Flash::error(trans('flash.controller.not_found', ['model' => 'Item Contract']));

            return redirect(route('itemContracts.index'));
        }

        $itemContract = $this->itemContractRepository->update($request->all(), $id);

        Flash::success(trans('flash.controller.update_success', ['model' => 'Item Contract']));

        return redirect(route('itemContracts.index'));
    }

    /**
     * Remove the specified ItemContract from storage.
     *
     * @param  int $id
     *
     * @return Response
     */
    public function destroy($id)
    {
        $itemContract = $this->itemContractRepository->findWithoutFail($id);

        if (empty($itemContract)) {
            Flash::error(trans('flash.controller.not_found', ['model' => 'Item Contract']));

            return redirect(route('itemContracts.index'));
        }

        $this->itemContractRepository->delete($id);

        Flash::success(trans('flash.controller.delete_success', ['model' => 'Item Contract']));

        return redirect(route('itemContracts.index'));
    }
}
